package com.javatest;

/**
 * @author LL
 * 给出一个排序好的数组和一个数，求数组中连续元素的和等于所给数的子数组
 * @create 2020-12-10 18:08
 */
public class Subject17 {

    public static void array(int[] num,int sum){

        for (int i = 0; i < num.length; i++) {
            int tmp = 0;
            int k = 0;
            int[] ints = new int[num.length];
            for (int j = i; j < num.length; j++) {
                if (num[j] > sum || num[j] == sum) {
                    continue;
                }
                if(tmp < sum){
                    tmp = tmp + num[j];
                    ints[k] = num[j];
                    k++;
                }else if (tmp == sum) {
                    System.out.print("子数组元素:");
                    for (int l = 0; l < k; l++) {
                        System.out.print(ints[l]+" ");
                    }
                    System.out.println("");
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        int s = 30;
        int sum = 30;
        int[] num = new int[s];
        for (int i = 0; i < s; i++) {
            num[i] = i;
        }
        array(num,sum);
    }
}

